/***************************************************************
|	File:		Vector4.cpp
|	Author:		Michael Mozdzierz
|	Date:		05/29/2014
|
***************************************************************/

#include "stdafx.h"
#include "Vector4.h"
#include "Vector3.h"
#include "Vector2.h"
#include <math.h>

#pragma region ctors

Vector4::Vector4(void)
{
	x = 0.f;
	y = 0.f;
	z = 0.f;
	w = 0.f;
}

Vector4::Vector4(float x, float y, float z, float w)
{
	this->x = x;
	this->y = y;
	this->z = z;
	this->w = w;
}

Vector4::Vector4(Vector2& v, float z, float w)
{
	this->x = v.x;
	this->y = v.y;
	this->z = z;
	this->w = w;
}

Vector4::Vector4(Vector3& v, float w)
{
	this->x = v.x;
	this->y = v.y;
	this->z = v.z;
	this->w = w;
}

#pragma endregion

#pragma region Unary operators
Vector4& Vector4::operator-()
{
	x = -x;
	y = -y;
	z = -z;
	w = -w;

	return *this;
}
Vector4& Vector4::operator += (Vector4& a)
{
	x += a.x;
	y += a.y;
	z += a.z;
	w += a.w;

	return *this;
}
Vector4& Vector4::operator -= (Vector4& a)
{
	x -= a.x;
	y -= a.y;
	z -= a.z;
	w -= a.w;

	return *this;
}
#pragma endregion

#pragma region binary operators
Vector4 operator +(Vector4& a, Vector4& b)
{
	return Vector4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
}

Vector4 operator -(Vector4& a , Vector4& b)
{
	return Vector4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
}

float operator *(Vector4& a , Vector4& b)
{
	return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
}

Vector4 operator* (Vector4& v,  float f)
{
	return Vector4(v.x * f, v.y * f, v.z * f, v.w * f);
}

Vector4 operator* (float f, Vector4& v)
{
	return Vector4(v.x * f, v.y * f, v.z * f, v.w * f);
}
#pragma endregion

#pragma region static functions

/*static*/ float Vector4::Dot(Vector3& a, Vector3& b)
{
	return a * b;
}
/*static*/ Vector4 Vector4::Normalize(Vector4& v)
{
	float length = (float)sqrt((v.x * v.x) + (v.y * v.y) + (v.z * v.z) + (v.w * v.w));

	return Vector4(v.x / length, v.y / length, v.z / length, v.w / length);
}

#pragma endregion